package com.wh;

import com.wh.util.ProxyServer;
import io.netty.channel.ChannelFuture;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class Proxy {
    private static Logger log = LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);

    public static void main(String[] args) throws InterruptedException {
        ProxyServer proxyServer = new ProxyServer("local.wuanwanghao.top", 3389, 9999);
        ChannelFuture init = proxyServer.init();
        try {
            init.sync();
            log.info("代理开启 代理端口为{},远程地址端口为{}", proxyServer.serverPort, proxyServer.remoteaddr + ":" + proxyServer.remotePort);
            //注意这里必须写关闭channel的future为同步方法,因为只有主线程结束才会关闭他会一直阻塞在这里,不然当服务启动过后就会结束主线程,整个任务接结束了
            init.channel().closeFuture().sync();
        } finally {
            init.channel().closeFuture().sync();
        }
        log.info("代理关闭");
    }
}
